Deprecate externalContext and migrate to Map-backed getObject/putObject#4070
Open
ramanathan1504 wants to merge 3 commits into
Open
Deprecate externalContext and migrate to Map-backed getObject/putObject#4070ramanathan1504 wants to merge 3 commits into
ramanathan1504 wants to merge 3 commits into
Conversation
…on for web lookups
vy
reviewed
Apr 12, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes servlet context propagation for web lookups when Log4j is initialized with a composite configuration (comma-separated log4jConfiguration locations), ensuring ${web:*} lookups (notably ${web:servletContextName}) resolve consistently between single-file and composite modes.
Changes:
- Update
Log4jContextFactory#getContext(..., List<URI> configLocations, ...)to correctly handleexternalContextpassed as aMap.Entry<String, Object>by routing it through theContextSelectorentry-based overload. - Add a regression test that initializes Log4j via
Log4jWebLifeCycleusing a composite config and asserts${web:servletContextName}resolves.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| log4j-jakarta-web/src/test/java/org/apache/logging/log4j/web/WebLookupTest.java | Adds a regression test covering ${web:servletContextName} resolution for composite configuration initialization. |
| log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java | Ensures Map.Entry external context is applied via the selector so web lookups can retrieve the ServletContext in composite mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…separated log4jConfiguration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR deprecates the externalContext methods in LoggerContext (API and Core) and replaces the internal storage with a ConcurrentHashMap accessible via putObject and getObject.
Key Changes:
1.Marked
setExternalContextandgetExternalContextas@Deprecated (since 2.27.0).2.Refactored
LoggerContextto use a Map-backed storage to prevent collisions between frameworks (e.g., Spring Boot and Log4j-Web).3.Maintained backward compatibility for Spring Boot by using a legacy key in the internal map.
Outcome:
This work resolves the servlet context resolution issue in composite configurations.
Fixes #2351